<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head th:replace="admin/fragment :: head('新增博客')">
</head>
<body>
<!--导航 ui表示ui inverted与当前色相反  attached表依附，去圆角  segment表片段-->
<div th:replace="admin/fragment :: menu(1)"></div>
<!--菜单中选中的样式  pointing-->
<div class="ui menu attached pointing right aligned">
    <div class="ui container">
        <div class="right menu">
            <a href="#" class="ui item active teal">发布</a>
            <a href="#" class="item">列表</a>
        </div>
    </div>
</div>
<!--中间内容-->
<div class="m-padded-tb-large m-container">
    <div class="ui container">
        <form action="#" method="post" id="blog-form" th:object="${blog}" th:action="@{/admin/blogs}" class="ui form">
            <input type="hidden" name="published">
            <input type="hidden" name="id" th:value="*{id}">
            <div class="field">
                <div class="ui left labeled input">
                    <!--compact 适应文本-->
                    <!--此处可以增加功能：圆仓/转载/翻译的各个字体都不一样，  即将该div的teal可变-->
                    <div class="ui selection compact teal basic dropdown label" style="z-index: 19">
                        <input type="hidden" value="原创" name="flag" th:value="${#strings.isEmpty(blog.flag) ? '原创' : blog.flag}">
                        <i class="dropdown icon"></i>
                        <div class="text">原创</div>
                        <div class="ui menu">
                            <div class="item" data-value="原创" th:selected="true">原创</div>
                            <div class="item" data-value="转载">转载</div>
                            <div class="item" data-value="翻译">翻译</div>
                        </div>
                    </div>
                    <input type="text" name="title" placeholder="标题" class="required" th:value="*{title}">
                </div>
            </div>
            <!--内容-->
            <div class="field">
                <div id="md-content">
                    <textarea name="content"  placeholder="博客内容" class="required" style="display: none" th:text="*{content} != null ? *{content}">

                        [TOC]

#### Disabled options

- TeX (Based on KaTeX);
- Emoji;
- Task lists;
- HTML tags decode;
- Flowchart and Sequence Diagram;

#### Editor.md directory

    editor.md/
            lib/
            css/
            scss/
            tests/
            fonts/
            images/
            plugins/
            examples/
            languages/
            editormd.js
            ...

```html
&lt;!-- English --&gt;
&lt;script src="../dist/js/languages/en.js"&gt;&lt;/script&gt;

&lt;!-- 繁體中文 --&gt;
&lt;script src="../dist/js/languages/zh-tw.js"&gt;&lt;/script&gt;
```
                    </textarea>
                </div>

            </div>
            
            <div class="two fields">
                <div class="field left">
                    <div class="ui labeled action input">
                        <label  class="ui compact teal basic label">分类</label>
                        <div class="ui selection dropdown fluid">
                            <input type="hidden" name="type.id" class="required" th:value="*{type}!=null?*{type.id}">
                            <!--th:value="*{type.id}"-->
                            <i class="ui dropdown icon"></i>
                            <div class="default text"></div>
                            <div class="menu">
                                <div th:each="type:${types}" class="item" th:data-value="${type.id}" th:text="${type.name}" >学习</div>
                                <!--/*-->
                                <div class="item" data-value="1">学习</div>
                                <div class="item" data-value="2">游戏</div>
                                <div class="item" data-value="3">生活</div>
                                <div class="item" data-value="4">其他</div>
                                <!--*/-->
                            </div>
                        </div>
                    </div>
                </div>
                <div class="field right aligned">
                    <div class="ui left labeled action input">
                        <label  class="ui compact teal basic label">标签</label>
                        <div id="multi-select" class="ui selection multiple search dropdown fluid" >
                            <input type="hidden" name="tagIds" class="required" th:value="*{tagIds}">
                            <i class="ui dropdown icon"></i>
                            <div class="default text"></div>
                            <div class="menu">
                                <div th:each="tag:${tags}" class="item" th:data-value="${tag.id}" th:text="${tag.name}">java</div>
                                <!--/*-->
                                <div class="item" data-value="1">java</div>
                                <div class="item" data-value="2">spring boot</div>
                                <div class="item" data-value="3">semantic ui</div>
                                <div class="item" data-value="4">normal</div>
                                <!--*/-->
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="field">
                <div class="ui left labeled input">
                    <label class="ui teal basic label">封面</label>
                    <input type="text" name="firstPic" placeholder="封面引用地址" class="required" th:value="*{firstPic}">
                </div>

            </div>


            <div class="inline fields">
                <div class="field">
                    <div class="ui checkbox">
                        <input type="checkbox" id="recommend"  name="recommend" class="hidden" checked th:checked="*{recommend}">
                        <label for="recommend">推荐</label>
                    </div>
                </div>
                <div class="field">
                    <div class="ui checkbox">
                        <input type="checkbox" id="shareInfo"  name="shareStatement" class="hidden" th:checked="*{shareStatement}">
                        <label for="shareInfo">转载声明</label>
                    </div>
                </div>
                <div class="field">
                    <div class="ui checkbox">
                        <input type="checkbox" id="appreciation"  name="appreciation" class="hidden" th:checked="*{appreciation}">
                        <label for="appreciation">赞赏</label>
                    </div>
                </div>
                <div class="field">
                    <div class="ui checkbox">
                        <input type="checkbox" id="comment"  name="canComment" class="hidden" th:checked="*{canComment}">
                        <label for="comment">留言</label>
                    </div>
                </div>
            </div>
            <div class="field">
                <label>博客描述</label>
                <textarea name="description"  id="description" th:text="*{description}"></textarea>
            </div>

            <div class="ui error message"></div>

            <div class="ui right aligned container">
                <button class="ui button" type="button" onclick="window.history.go(-1)">返回</button>
                <button id="save-btn" class="ui button secondary" type="button">保存</button>
                <button id="publish-btn" class="ui button teal" >发布</button>
            </div>
        </form>
    </div>
</div>


<!--底部  vertical垂直-->
<!--<div th:replace="admin/fragment :: footer"></div>-->

<div th:replace="admin/fragment :: script"></div>
<!--<script src="https://cdn.jsdelivr.net/npm/jquery/dist/jquery.min.js"></script>-->
<!--<script src="https://cdn.jsdelivr.net/npm/semantic-ui@2.4.2/dist/semantic.min.js"></script>-->
<!--<script src="../../static/lib/editormd/editormd.min.js"></script>-->

<script>
    // 初始化markdown编辑器
    var contentEditor;
    $(function() {
        contentEditor = editormd("md-content", {
            width   : "100%",
            height  : 640,
            syncScrolling : "single",
            // path    : "../../static/lib/editormd/lib/"
            path    : "[[@{/static/lib/editormd/lib/}]]"

        });

        /*
        // or
        testEditor = editormd({
            id      : "test-editormd",
            width   : "90%",
            height  : 640,
            path    : "../lib/"
        });
        */
    });


    $('.menu.toggle').click(function () {
        $('.m-item').toggleClass('m-mobile-hide');
    });

    $('.ui.dropdown').dropdown({
        on: 'hover'
    });

    $('#multi-select').dropdown({
        on: 'hover'
    });


    $('.ui.form').form({
        fields : {
            title : {
                identifier : 'title',
                rules : [{
                    type : 'empty',
                    prompt : '标题：请输入博客标题'
                }]
            },
            content : {
                identifier : 'content',
                rules : [{
                    type : 'empty',
                    prompt : '内容：请输入博客内容'
                }]
            },
            type : {
                identifier : 'type.id',
                rules : [{
                    type : 'empty',
                    prompt : '分类：请选择博客分类'
                }]
            },
            // tag : {
            //     identifier : 'tag',
            //     rules : [{
            //         type : 'empty',
            //         prompt : '标签：请选择博客标签'
            //     }]
            // },
            firstPic : {
                identifier : 'firstPic',
                rules : [{
                    type : 'empty',
                    prompt : '分类：请选择博客封面'
                }]
            },
            description : {
                identifier : 'description',
                rules : [{
                    type : 'empty',
                    prompt : '分类：请输入博客描述'
                }]
            },
        }
    });

    $("#save-btn").click(function () {
        $("[name='published']").val(false);
        $("#blog-form").submit();
    });
    $("#publish-btn").click(function () {
        $("[name='published']").val(true);
        $("#blog-form").submit();
    });



</script>


</body>

</html>